/*
 * File:   hashtabletest.c
 * Author: ossi
 *
 * Created on 06-Nov-2011, 19:53:36
 */

#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "hashtable.h"
#include "jsonparser.h"

/*
 * CUnit Test Suite
 */

int init_suite(void) {
    return 0;
}

int clean_suite(void) {
    return 0;
}

unsigned int ht_hash(wchar_t*);
void testHt() {
    
    
    hashtable* ht = ht_new();
    json_item* i = malloc(sizeof(json_item));
    i->data = "a";
    
    ht_put(ht,L"name", i);
    
    i = malloc(sizeof(json_item));
    i->data = "b";
    
    ht_put(ht,L"relations", i);
    
    CU_ASSERT(ht_hash(L"relations") == ht_hash(L"name"));
    json_item* res = ht_get(ht,L"name");
    CU_ASSERT(((char*)res->data)[0] == 'a');
    
    res = ht_get(ht,L"relations");
    CU_ASSERT(((char*)res->data)[0] == 'b')
    
    i = malloc(sizeof(json_item));
    i->data = "c";
    
    ht_put(ht,L"äöä jotain", i);
    
    res = ht_get(ht,L"äöä jotain");
    CU_ASSERT(((char*)res->data)[0] == 'c');
    
}

int main() {
    CU_pSuite pSuite = NULL;

    /* Initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* Add a suite to the registry */
    pSuite = CU_add_suite("hashtabletest", init_suite, clean_suite);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Add the tests to the suite */
    if ((NULL == CU_add_test(pSuite, "testHt_get", testHt))) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Run all tests using the CUnit Basic interface */
    printf("hashtabletest.c:");
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    CU_cleanup_registry();
    return CU_get_error();
}
